<html layout:decorate="~{default/layout}" xmlns:layout="http://www.w3.org/1999/xhtml">
<body>
<div layout:fragment="content">
    <div class="main-content-inner">
        <div class="breadcrumbs ace-save-state" id="breadcrumbs">
            <ul class="breadcrumb">
                <li>
                    <i class="ace-icon fa fa-home home-icon"></i>
                    <a href="#">主页</a>
                </li>
                <li class="active">系统管理</li>
                <li class="active">用户管理</li>
            </ul><!-- /.breadcrumb -->

        </div>

        <div class="page-content">
            <div class="search_condition">
                <form id="search-form">
                    <input class="search-data" name="Q_LIKE_loginName" type="text" placeholder="用户名称" th:value="${Q_LIKE_loginName}">

                    <select class="search-data" name="Q_EQ_role">
                        <option value="">选择角色</option>
                        <option th:each="role:${roles}" th:value="${role.id}" th:text="${role.name}"
                                th:selected="${role.id eq Q_EQ_role}"></option>
                    </select>
                    <button type="submit" id="search-btn" class="btn btn-primary btn-search" >搜索</button>
                </form>
            </div>

            <div class="main-body">
                <div id="toolbar" class="btn-group btn-group-sm">
                    <a type="button" class="btn btn-primary" data-toggle="modal" href="/system/user_add" data-target="#modal">新增</a>
                    <a type="button" onclick="editData('/system/user_edit','id')" class="btn btn-info">修改</a>
                    <a type="button" onclick="delDatas('/system/user_del')" class="btn btn-danger">删除</a>
                </div>
                <table id="dataTable" data-url="/system/user_data" data-page-list=[]  data-striped="true" data-pagination="true" data-page-size="10" data-cache="false">

                </table>
            </div>
        </div><!-- /.page-content -->
    </div>


    <script>
        //table字段
        var dataFormat = [{
            checkbox: true
        },{
            field:'id',
            title:'id',
            visible:false
        },{
            field: 'loginName',
            title: '用户名'
        },{
            field: 'role',
            title: '角色',
            formatter:function (value, row, index) {
                if(value!=null){
                    return value.name;
                }else{
                    return "";
                }
            }
        },{
            field: 'projectStr',
            title: '权限内项目'
        }, {
            field: "lastLoadTime",
            title: '上次登陆时间',
        formatter:function (value, row, index) {
            if(value!=null){
                return formatTimeStrap(value);
            }
            else{
                return "-";
            }
        }
        },{
            field: "createUser",
            title: '创建者',
            formatter:function (value, row, index) {
                if(value!=null){
                    return value.name;
                }else{
                    return "";
                }
            }
        }, {
            field: "menus",
            title: '权限分配',
                formatter: function (value, index, row) {
                    console.log(value.length);
                    var str = "";
                        if(value.length>1){
                            $(value).each(function(i,v){
                                console.log(v);
                                var name = v.title;
                                   str+='<input type="checkbox" checked disabled/><label class=" control-label">'+v.title+'</label>';
                            });
                            return str;
                        }else{
                            return "无权限";
                        }
                    }
        }];
        //初始化table
        window.onload = function () {
            getTable(dataFormat,"dataTable");
        };
        
//        function test() {
//            var a= $("#dataTable").bootstrapTable('getSelections');
//
//            if(a.length==1){
//
//                console.log(a[0].name);
//
//            }else{
//                alert("请选中一行");
//            }
//        }

//        function test2() {
//
//            $("#modal").modal({
//                remote:"/role/role_add"
//            });
//        }

    </script>

</div>
</body>
</html>